package com.eos.control.action.customer;

import java.util.List;

import com.eos.business.service.SysProductBusinessService;
import com.eos.common.tool.ConstantTool;
import com.eos.control.action.base.AbstractBaseAction;
import com.eos.orm.mybatis.model.ProductBrand;
import com.hf.utils.StringUtil;

public class UpdateBrandAction extends AbstractBaseAction {
	private static final long serialVersionUID = 4801503751988743450L;
	private Integer brandId;
	private String brandName;
	private String oldBrandName;
	private String brandDesc;
	
	public void setBrandId(Integer brandId) {
		this.brandId = brandId;
	}

	public void setBrandName(String brandName) {
		this.brandName = brandName;
	}

	public void setOldBrandName(String oldBrandName) {
		this.oldBrandName = oldBrandName;
	}

	public void setBrandDesc(String brandDesc) {
		this.brandDesc = brandDesc;
	}

	@Override
	public String execute() {
		try {
			if(null == brandId || brandId.longValue() <=0){
				statusCode = "300";
				message = "参数错误,保存信息失败!";
				return SUCCESS;
			}
			if(StringUtil.isEmpty(brandName)){
				statusCode = "300";
				message = "请输入新的品牌名称!";
				return SUCCESS;
			}
			ProductBrand brand = new ProductBrand();
			brand.setDealFlag(ConstantTool.DEAL_FALG_OK);
			brand.setStatus(ConstantTool.STATUS_OK);
			brand.setBrandName(brandName);
			SysProductBusinessService spbs = new SysProductBusinessService();
			if(!oldBrandName.equals(brandName)){
				List<ProductBrand> brandList = spbs.getProductBrandExample(brand);
				if(null != brandList && brandList.size() >0){
					statusCode = "300";
					message = "输入的品牌已经存在, 修改品牌信息失败!!";
				}
			}else{
				brand.setBrandDesc(brandDesc);
				brand.setId(brandId);
				String exeStatus = spbs.updateProductBrandSelective(brand);
				if("SUCCESS".equals(exeStatus)){
					statusCode = "200";
					message = "修改品牌信息成功!";
				}else{
					statusCode = "300";
					message = "系统繁忙, 修改品牌信息失败!";
				}
			}
		} catch (Exception e) {
		    e.printStackTrace();
		    statusCode = "300";
		    message = "系统异常,修改品牌信息失败!";
		}
		return SUCCESS;
	}
}
